<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			function TreeNode(val, left, right) {
				this.val = (val === undefined ? 0 : val)
				this.left = (left === undefined ? null : left)
				this.right = (right === undefined ? null : right)
			}
			let r = new TreeNode(1,
				new TreeNode(2,
					new TreeNode(4, null, null),
					new TreeNode(5, null, null)),
				new TreeNode(3,
					new TreeNode(6, null, null),
					new TreeNode(7, null, null)));
			var sumOfLeftLeaves = function(root) {
				let sum = 0;
				const dfs = (root) => {
					// 为空节点
					if (!root) return;
					// 是左子节点  并且左子节点的左右节点都为空 也就是说是叶子节点
					if (root.left && !root.left.left && !root.left.right) {
						// 找到左侧的叶子节点，记录累加值
						sum += root.left.val;
					}
					// 递归左右子树
					dfs(root.left);
					dfs(root.right);
				};
			 dfs(root);
				return sum;
			};
			console.log(sumOfLeftLeaves(r));
		</script>
	</body>
</html>
